<template>
  <!-- 初审页面 -->
  <div class="box">
    <div
      class="skeleton clearfix"
      style="position:relative"
    >

      <div class="skeleton_content">
        <div
          class="skeleton_title left"
          v-if="name.length<3"
        >
          {{((name.split("").reverse().join("")).substring(0,1)).split("").reverse().join("")}}
        </div>
        <div
          class="skeleton_title left"
          v-if="name.length>=3"
        >
          {{((name.split("").reverse().join("")).substring(0,2)).split("").reverse().join("")}}
        </div>
        <ul>
          <li>{{Originator.name}}</li>
          <li style="margin-bottom:10px">{{Originator.create_date}}</li>
        </ul>
        <img
          v-if="Originator.status==2"
          style="height:130px;position:absolute;right:10px;top:10px "
          src=""
        >
      </div>
      <ul style="padding:10px">
        <li>{{Originator.event_name}}</li>
        <li style="margin-bottom:45px;overflow-wrap:break-word;width:75vw">{{Originator.event_desc}}</li>
        <li style=" font-size: 13px;color:silver;">{{Originator.date}}</li>
      </ul>
      <div
        class="right"
        style="position:absolute;bottom:10px;right:15px"
        v-for="(item,i) in status"
        :key="i"
      >
        <p
          class="right"
          style="font-size:14px;color:silver;"
          v-if="Originator.status==item.index"
        ><span
            v-if="item.name=='通过'"
            style="color:dodgerblue;"
          >{{item.name}}</span><span
            v-else
            style="color:silver;"
          >{{item.name}}</span></p>
      </div>
    </div>
    <van-row style="background: #f8f4f4;">
      <p style="height:40px;line-height:40px;">奖扣对象</p>
    </van-row>
    <div
      class="public"
      v-for="(item,i) in list.Prizewinner"
      :key="i"
    >
      <span>{{item.name}}</span>
      <span v-if="item.code_b!=0"  style="margin-right:25px">{{D_name}}: {{item.code_b}}</span>
      <span
       
        v-if="item.code_c!=0 && ISC == 1"
      >{{C_name}}: {{item.code_c}}</span>
      
    </div>
    <div class="public"  v-if="list.isUpdate!=0">
      <span>审批分</span>
      <div style="display:inline-block"  v-if="code_d != 0">
       <i v-if="list.isPlus == 0&&status_active!=2&&list.isUpdate!=0&&code_d != 0"> － </i> 
      <i v-else-if="list.isPlus == 1&&status_active!=2&&list.isUpdate!=0&&code_d != 0">＋</i>
       <input type="tel" v-model="digit" inputmode="numeric" :placeholder="'点击修改'+D_name" style="border:none;width:85px">
       </div>
       <div v-show="checked" style="display:inline-block" v-if="ISC == 1&&status_active!=2&&list.isUpdate!=0 && code_c != 0">
          <i v-if="list.isPlus == 0"> － </i>
          <i v-else-if="list.isPlus == 1"> ＋ </i>
          <input
            v-if="list.isUpdate!=0 && ISC == 1&&code_c != 0"
            v-model="digit_c"
            type="number"
            style="border:none;width:85px"
            :placeholder="'点击修改'+C_name"
          /> 
       </div>
    </div>
    <!-- <div style="position:relative"
    class="approval_branch"
    v-if="list.isUpdate!=0"
    >
      <div class="van-cell van-field">
        <div class="van-cell__title van-field__label">
          <span>审批分</span>
        </div>
        <div class="van-cell__value van-field__value" v-if="code_d != 0">
          <div class="van-field__body">
            <input type="tel" inputmode="numeric" :placeholder="'点击修改'+D_name" class="van-field__control">
          </div>
        </div>
      </div>
      <span style="position: absolute;top: 10px;left: 116px;font-size: 15px;" v-if="list.isPlus == 0&&status_active!=2&&list.isUpdate!=0&&code_d != 0"> － </span> 
      <span style="position: absolute;top: 10px;left: 116px;font-size: 15px;" v-else-if="list.isPlus == 1&&status_active!=2&&list.isUpdate!=0&&code_d != 0">＋</span>
    
      <span
        v-show="checked"
        class="receive_C"
        
      >
        <span v-if="ISC == 1&&status_active!=2&&list.isUpdate!=0 && code_c != 0" style="position:relative;">
          <span style="position: absolute;top: -3.5px;left: -15px;font-size: 15px;" v-if="list.isPlus == 0"> － </span>
          <span style="position: absolute;top: -3.5px;left: -15px;font-size: 15px;" v-else-if="list.isPlus == 1"> ＋ </span>
          <input
            v-if="list.isUpdate!=0 && ISC == 1&&code_c != 0"
            v-model="digit_c"
            type="number"
            style="border:none;width:100%"
            :placeholder="'点击修改'+C_name"
          />
        </span> 
      </span>
    </div> -->
    
    <!-- 图片 -->
    <div
      v-if="fileList.length!=0"
      class="clearfix"
      style="padding:10px 0px 0px 16px"
    >
      <div
        class="left"
        style="width:100px;text-align:left"
      >图片</div>
      <div
        class="left"
        style="width:200px;text-align:left"
      >
        <van-uploader
          v-model="fileList"
          :deletable='false'
          :show-upload='false'
        />
      </div>
    </div>
    <div style="background: #f8f4f4;height:10px"></div>
    <div
      class="public"
    >
      <span
      >初审</span><span
      >{{Auditor.first}}</span>
    </div>
    <van-field
      v-if="Auditor.first_remark!=''"
      v-model="mess"
      rows="2"
      autosize
      label="审批意见"
      type="textarea"
      show-word-limit
    />
    <div
      class="public"
    >
      <span
      >终审</span><span
      >{{Auditor.end}}</span>
     
    </div>
     <van-field
        v-if="Auditor.end_remark!=''"
        v-model="mes"
        rows="2"
        autosize
        label="审批意见"
        type="textarea"
        show-word-limit
        :style="{padding:'15px',fontSize:'15px'}"
      />
    <van-cell-group v-if="type==1">
      <van-field
        v-model="message"
        rows="5"
        :style="{borderBottom:'1px solid #e3e1e185'}"
        label="审批意见"
        type="textarea"
        placeholder="请输入审批意见"
        show-word-limit
      />
    </van-cell-group>
    <van-row
      v-if="type==1"
      :style="{background:'#fff',padding:'15px 5px'}"
    >
      <van-button
        size="large"
        plain
        type="info"
        @click="showReject(list)"
      >驳回</van-button>
      <van-button
        size="large"
        type="info"
        :style="{marginLeft:'10px'}"
        @click="showAgree(list)"
      >同意</van-button>
    </van-row>
  </div>
</template>

<script type="text/javascript">
import {
  Row,
  Col,
  Popup,
  Cell,
  CellGroup,
  Field,
  Button,
  Uploader,
  Toast
} from "vant";
export default {
  data() {
    return {
      mess: "",
      mes: "",
      message: "",
      list: [],
      fileList: [],
      type: 0,
      status: [
        {
          index: 0,
          name: "初审中"
        },
        {
          index: 1,
          name: "终审中"
        },
        {
          index: 2,
          name: "通过"
        },
        {
          index: 3,
          name: "驳回"
        },
        {
          index: 4,
          name: "撤回"
        }
      ],
      C_name: "C分",
      D_name: "D分",
      Originator: [],
      checked: true,
      digit_c: "",
      digit: "",
      show: false,
      index: 0,
      name: "",
      Auditor: {},
      ISC:'',
      status_active:1,
      code_d:'',
      code_c:''
    };
  },
  created() {
    this.getUserId()
    this.status_active=this.$route.query.status;
    dd.biz.navigation.setTitle({
      title: "我的审核" //控制标题文本，空字符串表示显示默认文本
    });
  },
  beforeUpdate(){
    this.C_name = localStorage.getItem("c_name");
    this.D_name = localStorage.getItem("d_name");
  },
  methods: {
     //C分开关
    async getIsC(){
      let corpId = localStorage.getItem("custid");
      const res = await this.$http.get(
        `yuepoints/getIsC?corpId=${corpId}`
      );
      // localStorage.setItem("ISC", res.data.data.is_c_code);
      this.ISC = res.data.data.is_c_code
    },
     // 钉钉鉴权
    async show_js_api() {
      let corpId = localStorage.getItem("custid");
      // let corpId = this.$utils.getUrlKey("custid");
      let url = location.href.split("#")[0];
      const res = await this.$http.get(
        `dingapi/getJsapiConfig?corpId=${corpId}&url=${url}`
      );
      let config = res.data.data;
      localStorage.setItem("appId", config.agentId);
      dd.config({
        agentId: config.agentId,
        corpId: config.corpId,
        timeStamp: config.timeStamp,
        nonceStr: config.nonceStr,
        signature: config.signature,
        jsApiList: [
          "runtime.info",
          "biz.ding.post",
          "biz.ding.create",
          "biz.chat.pickConversation",
          "device.notification.prompt",
          "device.notification.confirm",
          "device.notification.alert",
          "biz.navigation.setRight",
          "biz.chat.open",
          "biz.util.open",
          'biz.util.openLink',
          "biz.user.get",
          "biz.contact.choose",
          "biz.telephone.call",
          "biz.util.uploadImage",
          // "device.accelerometer.watchShake",
          // "biz.map.locate",
          // "device.geolocation.get",
          "biz.customContact.choose",
          "biz.contact.complexPicker",
          "biz.contact.departmentsPicker",
        ]
      });
    },
     // 自定义名称存储
    async getCustomName() {
      let corpId = localStorage.getItem("custid");
      const res = await this.$http.get(
        `yuepoints/getCustomName?corpId=${corpId}`
      );
      if (res.data.errcode == "0000") {
        if (res.data.data.c_name == "") {
          localStorage.setItem("c_name", "C分");
        } else {
          localStorage.setItem("c_name", res.data.data.c_name);
        }
        if (res.data.data.d_name == "") {
          localStorage.setItem("d_name", "D分");
        } else {
          localStorage.setItem("d_name", res.data.data.d_name);
        }
      } else {
        localStorage.setItem("c_name", "C分");
        localStorage.setItem("d_name", "D分");
      }
    },
    async getUserId() {
      let Corp_Id = localStorage.getItem("custid");
      let User_Id = localStorage.getItem("userId");
      let corpId = this.$utils.getUrlKey("custid");
      if(corpId == null || corpId == "undefined"){
        corpId = Corp_Id
      }else{
        localStorage.setItem("custid", corpId);
      }
      var _this = this;
      let code = '';
      if (User_Id && User_Id != "undefined" && User_Id != null) {
        if (Corp_Id != corpId) {
         await dd.runtime.permission.requestAuthCode({
                corpId: corpId,
                onSuccess: function(result) {
                  code = result.code
                },
                onFail: function(err) {
                }
              });
          _this.$http
              .get(
                `dingapi/signIn?corpId=${corpId}&code=${code}`
              )
              .then(res => {
                localStorage.setItem("userId", res.data.data.dd_id);
                localStorage.setItem("custid", corpId);
                _this.getCustomName();
                _this.auditDetails();
                _this.show_js_api();
                _this.getIsC();
              })
              
        }else{
            _this.auditDetails();
            _this.show_js_api();
            _this.getIsC();
        }
      } else {
         await dd.runtime.permission.requestAuthCode({
                corpId: corpId,
                onSuccess: function(result) {
                  code = result.code
                },
                onFail: function(err) {
                }
              });
          _this.$http
            .get(
              `dingapi/signIn?corpId=${corpId}&code=${code}`
            )
            .then(res => {
              localStorage.setItem("userId", res.data.data.dd_id);
              localStorage.setItem("custid", corpId);
              _this.getCustomName();
              _this.auditDetails();
              _this.show_js_api();
              _this.getIsC();
            })
      }
    },
    onChange(index) {
      this.index = index;
    },
    show_file(img) {
      this.show = true;
    },
    // 驳回
    async showReject(list) {
      const id = list.id;
      const desc = this.message;
      // if (desc == "") {
      //   Toast("请输入驳回意见");
      //   return false;
      // }
      let userId = localStorage.getItem("userId");
      let corpId = localStorage.getItem("custid");
       Toast.loading({
          message: "数据提交中",
          forbidClick: true,
          loadingType: "spinner"
        });
      const res = await this.$http.get(
        `yuepoints/toExamine?corpId=${corpId}&userId=${userId}&id=${id}&status=3&desc=${desc}&type=0`
      );
      if (res.data.errcode == "0000") {
        Toast.success('驳回成功');
        this.$router.push({ path: "/toExamine" });
      } else {
        this.$toast(res.data.errmsg);
      }
    },
    // 同意
    async showAgree(list) {
      const id = list.id;
      const desc = this.message;
      // if (desc == "") {
      //   Toast("请输入审批意见");
      //   return false;
      // }
      const code_d = this.digit;
      const code_c = this.digit_c;
      let userId = localStorage.getItem("userId");
      let corpId = localStorage.getItem("custid");
       Toast.loading({
          message: "数据提交中",
          forbidClick: true,
          loadingType: "spinner"
        });
      const res = await this.$http.get(
        `yuepoints/toExamine?corpId=${corpId}&userId=${userId}&id=${id}&status=1&desc=${desc}&type=0&codeD=${code_d}&codeC=${code_c}`
      );
      if (res.data.errcode == "0000") {
         Toast.success('审核成功');
        this.$router.push({ path: "/toExamine" });
      } else {
        this.$toast(res.data.errmsg);
      }
    },
    async auditDetails() {
      this.type = this.$route.query.status;
      let id = this.$route.query.id;
      let userId = localStorage.getItem("userId");
      let corpId = localStorage.getItem("custid");
      if (userId == null || userId == "undefined") {
        // Toast("请在钉钉工作台悦积分入口进入查看");
        this.$router.push("/error");
        return false;
      }
      const res = await this.$http.get(
        `yuepoints/auditDetails?corpId=${corpId}&userId=${userId}&id=${id}`
      );
      const {
        data: { Auditor, Originator, image }
      } = res.data;
      this.Originator = Originator;
      this.name = this.Originator.name;
      this.list = res.data.data;
      this.code_d = this.list.Prizewinner[0].code_b
      this.code_c = this.list.Prizewinner[0].code_c
      this.Auditor = this.list.Auditor;
      this.mess = Auditor.first_remark;
      this.mes = Auditor.end_remark;
    
      let List = [];
      List = image;
      for (let i = 0; i < List.length; i++) {
        this.fileList.push({ url: List[i] });
      }
    }
  },
  components: {
    [Row.name]: Row,
    [Col.name]: Col,
    [Popup.name]: Popup,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Field.name]: Field,
    [Button.name]: Button,
    [Uploader.name]: Uploader
  }
};
</script>

<style lang="less" scoped>
.box {
  overflow-y: hidden;
  font-size: 15px;
  padding-bottom: 55px;
  text-align: left;
  i{
    font-style: normal;
    font-size: 16px;
  }
  //  .approval_branch{
  //   /deep/ .van-cell__value.van-field__value{
  //     margin-left: 15px;
  //   }
  //  }
   /deep/ .van-field__body {
    padding-left: 10px;
  }
  input::-webkit-input-placeholder {
    color: #b0b0b2;
  }
  input::-moz-input-placeholder {
    color: #b0b0b2;
  }
  input::-ms-input-placeholder {
    color: #b0b0b2;
  }
  .receive_C {
    display: inline-block;
    position: absolute;
    top: 50%;
    right: 0px;
    width: 100px;
    transform: translate(-50%, -50%);
  }
  /deep/ .van-cell {
    //   padding-left: 0px;
    text-align: left;
  }
  /deep/ .van-row {
    padding: 0px 16px;
    text-align: left;
  }

  /deep/ .van-switch {
    margin-top: 5px;
    float: right;
  }
  /deep/ .van-button--large {
    width: 48%;
    height: 40px;
    line-height: 40px;
  }
  .public {
    height: 5vh;
    line-height: 5vh;
    background: #fff;
     border-bottom: 1px solid #e3e1e185;
    padding: 10px 16px;
    span:nth-child(1){
      display: inline-block;
      width: 100px;
    }
  }
  p {
    margin: 0px;
  }
  .row_top {
    background-color: #fff;
    height: 80px;
    line-height: 40px;
  }
  .skeleton {
    background: #fff;
    padding: 20px 20px 10px;
    text-align: left;
    .skeleton_title {
      color: #fff;
      width: 48px;
      height: 48px;
      border-radius: 50%;
      text-align: center;
      line-height: 48px;
      background: rgb(89, 209, 255);
      font-size: 16px;
      margin-right: 15px;
      // border: 1px solid silver
    }
    .skeleton_content {
      li {
        font-size: 16px;
      }
      li:nth-child(2) {
        font-size: 13px;
        color: silver;
      }
      li:nth-child(5),
      li:nth-child(6) {
        font-size: 13px;
        margin-top: 10px;
        color: rgb(117, 116, 116);
      }
    }
    /deep/ .van-icon {
      color: silver;
      font-size: 19px;
    }
  }
  .left {
    float: left;
  }
  .right {
    float: right;
  }
}
.clearfix::after {
  content: "";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.clearfix {
  zoom: 1;
}
</style>
